package com.crm.system.service.impl.sys;

import com.crm.common.model.DhPageInfo;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.sys.permissionManagement.SysInvoiceCompany;
import com.crm.model.vo.sys.InvoiceCompanyVO;
import com.crm.service.sys.permissionManagement.InvoiceCompanyDbService;
import com.crm.system.service.sys.InvoiceCompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author:chaifuyou
 * @Date: 2021/7/23 8:43
 */
@Service
public class InvoiceCompanyServiceImpl implements InvoiceCompanyService {

    @Autowired
    private InvoiceCompanyDbService invoiceCompanyDbService;

    /**
     * 新增开票公司
     * @param sysInvoiceCompany
     */
    @Override
    public void addCompanyIssueInvoice(SysInvoiceCompany sysInvoiceCompany) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        sysInvoiceCompany.setInvoiceCompanyId(CommonUtils.getGUID());
        sysInvoiceCompany.setCreatePeopleId(userAccount.getAccountId());
        sysInvoiceCompany.setCreateTm(new Date());
        invoiceCompanyDbService.addCompanyIssueInvoice(sysInvoiceCompany);
    }

    /**
     * 查询开票公司列表
     * @param pageIndex
     * @param pageSize
     * @param companyName
     * @return
     */
    @Override
    public DhPageInfo<InvoiceCompanyVO> selectInvoiceCompanyList(Integer pageIndex, Integer pageSize, String companyName,Integer companyStatus) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<InvoiceCompanyVO> customerList = invoiceCompanyDbService.selectInvoiceCompanyList(companyName,companyStatus);
        PageInfo<InvoiceCompanyVO> pageInfo = new PageInfo<InvoiceCompanyVO>(customerList);
        return new DhPageInfo<InvoiceCompanyVO>(pageInfo, customerList);
    }

    /**
     * 删除开票公司
     * @param companyId
     */
    @Override
    public void delInvoiceCompany(String companyId) {
        invoiceCompanyDbService.delInvoiceCompany(companyId);
    }

    /**
     * 停用开票公司
     * @param companyId
     */
    @Override
    public void stopInvoiceCompany(String companyId,Integer type) {
        invoiceCompanyDbService.stopInvoiceCompany(companyId,type);
    }

    /**
     * 根据分公司查询开票公司列表
     * @param companyId
     * @return
     */
    @Override
    public List<InvoiceCompanyVO> selectCompanyInvoiceCompany(String companyId) {
        return invoiceCompanyDbService.selectCompanyInvoiceCompany(companyId);
    }
}
